package bean.task;

import dao.task.TaskDAO;
import entity.task.Task;

import javax.enterprise.context.ApplicationScoped;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.inject.Inject;

@ManagedBean
@ViewScoped
public class TaskBean {
	
	@Inject
	private TaskDAO taskDAO;
	
	private Long id;
	
	private Task task;
	
	public void load() {
		if (null == id) {
			task = new Task();
		} else {
			task = taskDAO.findById(id, false);
		}
	}
	
	public String save() {
		taskDAO.makePersistent(task);
		taskDAO.flush();
		return "/content/task/list?faces-redirect=true";
	}
	
	public Long getId() {
		return id;
	}
	
	public void setId(Long id) {
		this.id = id;
	}
	
	public Task getTask() {
		return task;
	}
	
	public void setTask(Task task) {
		this.task = task;
	}

}

